package combat;

import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;

import actives.ActiveManager;
import actives.ActiveType;

import skills.Skill;
import skills.SkillHandler;
import skills.Skills;

public class Toughness {

	public static void meleeCombat(EntityDamageByEntityEvent event) {
		Player damager = (Player) event.getDamager();
		ActiveManager.activate(damager, ActiveType.TOUGHNESS, event.getEntity());
		Skill toughness = SkillHandler.getSkill(damager, Skills.TOUGHNESS);
		double damage = event.getDamage();
		damage = damage * (1 + toughness.level() / 500.0);
		event.setDamage((int) damage);
		toughness.addExp(event.getDamage());
	}

	public static void toughness(EntityDamageEvent event) {
		Player player = (Player) event.getEntity();
		Skill toughness = SkillHandler.getSkill(player, Skills.TOUGHNESS);
		if (toughness.level() >= 750) {
			ResistanceManager.buff(player);
		}
		switch (event.getCause()) {
		case DROWNING:
		case STARVATION:
		case SUFFOCATION:
			if (toughness.level() >= 250) {
				event.setDamage(event.getDamage() / 2);
			}
			break;
		default:
			break;
		}
		toughness.addExp(event.getDamage());
	}
}
